unit uCSTSitTrib;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy, dxSkinGlassOceans,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
  dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver,
  dxSkinPumpkin, dxSkinSeven, dxSkinSharp, dxSkinSilver, dxSkinSpringTime,
  dxSkinStardust, dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, dxPSGlbl, dxPSUtl, dxPSEngn, dxPrnPg, dxBkgnd, dxWrap,
  dxPrnDev, dxPSCompsProvider, dxPSFillPatterns, dxPSEdgePatterns,
  dxPSPDFExportCore, dxPSPDFExport, cxDrawTextUtils, dxSkinscxPCPainter,
  dxPSPrVwStd, dxPSPrVwAdv, dxPSPrVwRibbon, dxPScxEditorProducers,
  dxPScxExtEditorProducers, dxPScxPageControlProducer, dxSkinsdxBarPainter,
  ImgList, dxBar, dxPSCore, dxPScxCommon, dxPScxGrid6Lnk, cxEdit, dxSkinsForm,
  cxClasses, dxRibbon, cxContainer, cxGroupBox, cxRadioGroup, cxStyles,
  cxCustomData, cxFilter, cxData, cxDataStorage, DB, cxDBData, cxGridLevel,
  cxGridCardView, cxGridDBCardView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGridCustomView, cxGrid, Grids, DBGrids, ComCtrls,
  JvExControls, JvXPCore, JvXPButtons, StdCtrls, JvExStdCtrls, JvGroupBox, clsTributacoes,
  Buttons, JvExButtons, JvButtons, ExtCtrls, JvExExtCtrls, JvRadioGroup, JvLabel;

type
  TfCSTSitTrib = class(TForm)
    dxRibbon1: TdxRibbon;
    dxRibbon1Tab1: TdxRibbonTab;
    dxSkinController1: TdxSkinController;
    cxEditRepository1: TcxEditRepository;
    dxComponentPrinter1: TdxComponentPrinter;
    dxComponentPrinter1Link1: TdxGridReportLink;
    dxBarManager1: TdxBarManager;
    dxBarManager1Bar1: TdxBar;
    dxBarLargeButton1: TdxBarLargeButton;
    dxBarLargeButton2: TdxBarLargeButton;
    dxBarLargeButton3: TdxBarLargeButton;
    dxBarLargeButton4: TdxBarLargeButton;
    dxBarLargeButton5: TdxBarLargeButton;
    dxBarButton1: TdxBarButton;
    dxBarLargeButton6: TdxBarLargeButton;
    dxBarLargeButton7: TdxBarLargeButton;
    dxBarLargeButton8: TdxBarLargeButton;
    dxBarLargeButton9: TdxBarLargeButton;
    dxBarLargeButton10: TdxBarLargeButton;
    cxImageList1: TcxImageList;
    cxImageList2: TcxImageList;
    JvGroupBox2: TJvGroupBox;
    pgControlCSTTrib: TPageControl;
    tgCSTICMS: TTabSheet;
    tgCSTIPI: TTabSheet;
    tgCSTPIS: TTabSheet;
    tgCSTCOFINS: TTabSheet;
    tgCSTISSQN: TTabSheet;
    JvGroupBox1: TJvGroupBox;
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1DBTableView1Column2: TcxGridDBColumn;
    cxGrid1DBTableView1Column1: TcxGridDBColumn;
    cxGrid1DBCardView1: TcxGridDBCardView;
    cxGrid1DBCardView1Row1: TcxGridDBCardViewRow;
    cxGrid1DBCardView1Row2: TcxGridDBCardViewRow;
    cxGrid1DBCardView1Row3: TcxGridDBCardViewRow;
    cxGrid1Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    cxGridDBTableView1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBCardView1: TcxGridDBCardView;
    cxGridDBCardViewRow1: TcxGridDBCardViewRow;
    cxGridDBCardViewRow2: TcxGridDBCardViewRow;
    cxGridDBCardViewRow3: TcxGridDBCardViewRow;
    cxGridLevel1: TcxGridLevel;
    cxGrid3: TcxGrid;
    cxGridDBTableView2: TcxGridDBTableView;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBCardView2: TcxGridDBCardView;
    cxGridDBCardViewRow4: TcxGridDBCardViewRow;
    cxGridDBCardViewRow5: TcxGridDBCardViewRow;
    cxGridDBCardViewRow6: TcxGridDBCardViewRow;
    cxGridLevel2: TcxGridLevel;
    cxGrid4: TcxGrid;
    cxGridDBTableView3: TcxGridDBTableView;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBCardView3: TcxGridDBCardView;
    cxGridDBCardViewRow7: TcxGridDBCardViewRow;
    cxGridDBCardViewRow8: TcxGridDBCardViewRow;
    cxGridDBCardViewRow9: TcxGridDBCardViewRow;
    cxGridLevel3: TcxGridLevel;
    cxGrid5: TcxGrid;
    cxGridDBTableView4: TcxGridDBTableView;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBCardView4: TcxGridDBCardView;
    cxGridDBCardViewRow10: TcxGridDBCardViewRow;
    cxGridDBCardViewRow11: TcxGridDBCardViewRow;
    cxGridDBCardViewRow12: TcxGridDBCardViewRow;
    cxGridLevel4: TcxGridLevel;
    cxGrid6: TcxGrid;
    cxGridDBTableView5: TcxGridDBTableView;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBCardView5: TcxGridDBCardView;
    cxGridDBCardViewRow13: TcxGridDBCardViewRow;
    cxGridDBCardViewRow14: TcxGridDBCardViewRow;
    cxGridDBCardViewRow15: TcxGridDBCardViewRow;
    cxGridLevel5: TcxGridLevel;
    pnlOpcoesRelatorio: TPanel;
    Panel16: TPanel;
    rgTipoRelatorio: TcxRadioGroup;
    ICMS: TdxGridReportLink;
    IPI: TdxGridReportLink;
    PIS: TdxGridReportLink;
    COFINS: TdxGridReportLink;
    ISSQN: TdxGridReportLink;
    Origem: TdxGridReportLink;
    cxGrid7: TcxGrid;
    cxGridDBTableView6: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBCardView6: TcxGridDBCardView;
    cxGridDBCardViewRow16: TcxGridDBCardViewRow;
    cxGridDBCardViewRow17: TcxGridDBCardViewRow;
    cxGridDBCardViewRow18: TcxGridDBCardViewRow;
    cxGridLevel6: TcxGridLevel;
    dxBarLargeButton11: TdxBarLargeButton;
    TodasCST: TdxGridReportLink;
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    JvLabel1: TJvLabel;
    Image1: TImage;
    btOkAjudaTipoTributacao: TJvHTButton;
    JvHTButton1: TJvHTButton;
    cxGridDBTableView5Column1: TcxGridDBColumn;
    procedure dxBarLargeButton8Click(Sender: TObject);
    procedure dxBarLargeButton7Click(Sender: TObject);
    procedure pgControlCSTTribChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure btOkAjudaTipoTributacaoClick(Sender: TObject);
    procedure JvHTButton1Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    strict private
    constructor Create(AOwner: TComponent);
  strict private
    class var FInstance: TfCSTSitTrib;
  public
    class function GetInstance: TfCSTSitTrib;
    { Public declarations }
  end;

var
  fCSTSitTrib: TfCSTSitTrib;
  clsTributacoes  : TCLtributacoes;

implementation

uses uDMCI;

{$R *.dfm}

procedure TfCSTSitTrib.dxBarLargeButton7Click(Sender: TObject);
begin
  close;
end;

procedure TfCSTSitTrib.dxBarLargeButton8Click(Sender: TObject);
begin
  pnlOpcoesRelatorio.Visible := true;
  pnlOpcoesRelatorio.Left    := 207;
  rgTipoRelatorio.ItemIndex  := 0;
end;

procedure TfCSTSitTrib.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  clsTributacoes.Free;
  Action := caFree;
  FInstance := nil;
end;

procedure TfCSTSitTrib.FormCreate(Sender: TObject);
begin
  clsTributacoes := TCLtributacoes.Create;
end;

procedure TfCSTSitTrib.pgControlCSTTribChange(Sender: TObject);
begin
  case pgControlCSTTrib.ActivePageIndex of
    0 : begin
          DMCI.CODIGOST.Close;
          DMCI.CODIGOST.databasename := DMCI.dbCentralImpostos.DatabaseName;
          DMCI.CODIGOST.Active       := false;
          clsTributacoes.ConsultarCSTRel(DMCI.CODIGOST);
          DMCI.CODIGOST.SQL.Add(' WHERE (DESCRICAO LIKE ('+#39+'ICMS%'+#39+')) OR (DESCRICAO LIKE ('+#39+'CSOSN%'+#39+'))');
          DMCI.CODIGOST.Open;
        end;
    1 : begin
          DMCI.CODIGOST.Close;
          DMCI.CODIGOST.databasename := DMCI.dbCentralImpostos.DatabaseName;
          DMCI.CODIGOST.Active       := false;
          clsTributacoes.ConsultarCSTRel(DMCI.CODIGOST);
          DMCI.CODIGOST.SQL.Add(' WHERE DESCRICAO LIKE ('+#39+'IPI%'+#39+')');
          DMCI.CODIGOST.Open;
        end;
    2 : begin
          DMCI.CODIGOST.Close;
          DMCI.CODIGOST.databasename := DMCI.dbCentralImpostos.DatabaseName;
          DMCI.CODIGOST.Active       := false;
          clsTributacoes.ConsultarCSTRel(DMCI.CODIGOST);
          DMCI.CODIGOST.SQL.Add(' WHERE DESCRICAO LIKE ('+#39+'PIS%'+#39+')');
          DMCI.CODIGOST.Open;
        end;
    3 : begin
          DMCI.CODIGOST.Close;
          DMCI.CODIGOST.databasename := DMCI.dbCentralImpostos.DatabaseName;
          DMCI.CODIGOST.Active       := false;
          clsTributacoes.ConsultarCSTRel(DMCI.CODIGOST);
          DMCI.CODIGOST.SQL.Add(' WHERE DESCRICAO LIKE ('+#39+'COFINS%'+#39+')');
          DMCI.CODIGOST.Open;
        end;
    4 : begin
          DMCI.CODIGOST.Close;
          DMCI.CODIGOST.databasename := DMCI.dbCentralImpostos.DatabaseName;
          DMCI.CODIGOST.Active       := false;
          clsTributacoes.ConsultarCSTRel(DMCI.CODIGOST);
          DMCI.CODIGOST.SQL.Add(' WHERE DESCRICAO LIKE ('+#39+'ISSQN%'+#39+')');
          DMCI.CODIGOST.Open;

        end;
  end;
end;

procedure TfCSTSitTrib.SpeedButton1Click(Sender: TObject);
begin
  JvHTButton1Click(Self);
end;

procedure TfCSTSitTrib.btOkAjudaTipoTributacaoClick(Sender: TObject);
begin
  pnlOpcoesRelatorio.Visible := false;
  case rgTipoRelatorio.ItemIndex of
    0 : Origem.Preview(True);
    1 : begin
          case pgControlCSTTrib.ActivePageIndex of
            0 : ICMS.Preview(True);
            1 : IPI.Preview(True);
            2 : PIS.Preview(True);
            3 : COFINS.Preview(True);
            4 : ISSQN.Preview(True);
          end;
        end;
    2 : begin
          DMCI.CodigoSTRel.Close;
          DMCI.CodigoSTRel.databasename := DMCI.dbCentralImpostos.DatabaseName;
          DMCI.CodigoSTRel.Active       := false;
          clsTributacoes.ConsultarCSTRel(DMCI.CodigoSTRel);
          DMCI.CodigoSTRel.Open;
          TodasCST.Preview(True);
        end;
  end;
end;

constructor TfCSTSitTrib.Create(AOwner: TComponent);
begin
  inherited;
end;

class function TfCSTSitTrib.GetInstance: TfCSTSitTrib;
begin
  If FInstance = nil Then
  begin
    FInstance := uCSTSitTrib.TfCSTSitTrib.Create(Application);
  end else
    FInstance.BringToFront;
  Result := FInstance;
end;

procedure TfCSTSitTrib.JvHTButton1Click(Sender: TObject);
begin
  pnlOpcoesRelatorio.Visible := false;
end;

end.
